#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 105;
string s;
int main() {
  cin >> n;
  while (n--) {
    cin >> s;
    int ab = 0, ba = 0;
    int state = 0;
    for (int i = 0; i < s.size() - 1; ++i) {
      if (s[i + 1] - s[i] == 1) {  // AB
        ab++;
      } else if (s[i + 1] - s[i] == -1) {  // BA
        ba++;
      }
    }
    if (ab > ba) {
      s[0] = 'b';
    } else if (ab < ba) {
      s[0] = 'a';
    }
    // cout << ab << ' ' << ba << endl;
    cout << s << '\n';
  }
}
